﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MazeRunner.Graphics;
using OpenTK.Graphics.OpenGL;

namespace OpenTK2.Graphics
{
	public class Billboard
	{
		public float xPos;
		public float yPos;
		public float rot; //which direction this item is facing internally, will be converted to one of 8 directional sprites
		public int textureId; //which texture it uses

		public void Draw(float playerRot)
		{
			GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
			GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);

			GL.BindTexture(TextureTarget.Texture2D, OpenGLSetup.textures[0]);

			GL.Begin(BeginMode.Quads);
			GL.PushMatrix();
			GL.Translate(xPos, 0, yPos);

			float xrotrad = (playerRot / 180) * 3.141592654f;
			float xRot = (float)Math.Sin(xrotrad) * 2;
			float zRot = (float)Math.Cos(xrotrad) * 2;

			GL.Normal3(0.0, 0.0, 1.0);
			GL.TexCoord2(0, 0);
			GL.Vertex3(xPos * 2 + xRot, -1, yPos * 2 + 2.0 + zRot);
			GL.TexCoord2(1, 0);
			GL.Vertex3(xPos * 2 + 2.0 + xRot, -1, yPos * 2 + zRot);
			GL.TexCoord2(1, 1);
			GL.Vertex3(xPos * 2 + 2.0 + xRot, 1, yPos * 2 + zRot);
			GL.TexCoord2(0, 1);
			GL.Vertex3(xPos * 2 + xRot, 1, yPos * 2 + 2.0 + zRot);

			GL.PopMatrix();
			GL.End();
		}
	}
}
